Storing the Current Printer Configuration
QuickDraw GX sends theGXOpenConnection
message to open a connection with a printing device. You can override this message, which is described on page 4-131 in the chapter "Printing Messages," to perform any special operations that you need to do at the time of connection.The ImageWriter II printer driver overrides the
GXOpenConnection
message to update the printer configuration that is stored with the desktop printer. It first sends a query to the printing device for its hardware configuration, which includes information about the sheet-feeder and color-ribbon options. It then stores that information with the desktop printer. This message override, theSD_OpenConnection
function, is shown in
Listing 3-8.Listing 3-8 Opening the connection with the printing device
OSErr SD_OpenConnection(void) { OSErr anErr; /* first, open the connection the standard way */ anErr = Forward_GXOpenConnection(); nrequire(anErr, OpenConnection); /* then, bring the desktop-printer configuration information up to date */ anErr = UpdateConfiguration(); nrequire(anErr, UpdateConfiguration); return(noErr); /* exception handling */ UpdateConfiguration: GXCleanupOpenConnection(); OpenConnection: return(anErr); }TheSD_OpenConnection
function queries and stores the hardware configuration by calling a local function,UpdateConfiguration
. This function, which is shown in Listing 3-9, calls theFetchStatusString
function to query the ImageWriter II and then stores the information in the printer configuration file.Listing 3-9 Getting information about the configuration of the printing device
OSErr UpdateConfiguration(void) { Str32 deviceName; OSErr anErr = noErr; ImageWriterConfigHandle configHandle; ImageWriterConfigPtr configPtr; Boolean isImageWriterII = false; ResType commType; /* find out printer name and how the printer is connected */ GXGetPrinterName(GXGetJobOutputPrinter(GXGetJob()), deviceName); anErr = GXFetchDTPData(deviceName, gxDeviceCommunicationsType, gxDeviceCommunicationsID, (Handle*)&configHandle); nrequire(anErr, FetchCommType); commType = **(ResType**)configHandle; DisposHandle((Handle) configHandle); /* store the communications type for future use */ { SpecGlobalsHdl hGlobals = GetMessageHandlerInstanceContext(); (**hGlobals).commType = commType; } /* find out the original configuration */ if (GXFetchDTPData(deviceName, kImageWriterConfigType, kImageWriterConfigID, (Handle*)&configHandle) == noErr) { /* remember that it was an IW2 */ configPtr = *configHandle; isImageWriterII = configPtr->isImageWriterII; DisposeHandle((Handle) configHandle); /* If this is not an ImageWriter II, bail out now because the timeout takes two minutes! */ if (!isImageWriterII) return(noErr); } else { /* if not sure yet, assume IW2 for PAP and IW1 otherwise */ if (commType == 'PPTL') isImageWriterII = true; } /* make a handle to hold configuration info for the printer */ configHandle = (ImageWriterConfigHandle) NewHandle(sizeof(ImageWriterConfigRecord) ); anErr = MemError(); nrequire(anErr, NewHandle); /* set up the default for the device */ configPtr = *configHandle; configPtr->hasColorRibbon = false; configPtr->hasSheetFeeder = false; configPtr->isImageWriterII = true; { short statusReturn; /* query the device */ anErr = FetchStatusString(&statusReturn, (commType == 'PPTL')); /* Scan the status string looking for information about printer kind and options. */ configPtr = *configHandle; if ( anErr == gxAioTimeout ) { /* If you don't know what kind of printer it is and the request timed out, assume that it is an IW1. */ if (!isImageWriterII) { anErr = noErr; configPtr->isImageWriterII = false; } } else { configPtr->hasColorRibbon = (statusReturn & (0x1000 >> kColorRibbonBit)) != 0; configPtr->hasSheetFeeder = (statusReturn & (0x1000 >> kSheetFeederBit)) != 0; } nrequire(anErr, FetchStatusString); } /* write out the new configuration */ anErr = GXWriteDTPData(deviceName, kImageWriterConfigType, kImageWriterConfigID, (Handle)configHandle); /* exception handling */ FetchStatusString: DisposHandle((Handle) configHandle); NewHandle: FetchCommType: return(anErr); }TheUpdateConfiguration
function first calls theGXFetchDTPData
function to access the communications type that is stored for the printer with the desktop printer.UpdateConfiguration
next callsGXFetchDTPData
to determine with which kind of printer it is communicating. Then,UpdateConfiguration
calls theFetchStatusString
function. This is a local function that sends a query to the hardware device and receives a status string back from it.UpdateConfiguration
examines the status string to determine whether the printer has a sheet feeder or a color ribbon. Finally,UpdateConfiguration
calls theGXWriteDTPData
function to store the information that it has updated in the desktop printer.Desktop printers are described in Inside Macintosh: QuickDraw GX Printing. The
GXFetchDTPData
function is described on page 5-27 and theGXWriteDTPData
function is described on page 5-26 in the chapter "Printing Functions for Message Overrides."
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help